/**
 * 
 */
package com.HibernateRecipes.Chapter5.DAO;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.Hib.Util.SessionManager;
import com.HibernateRecipes.Chapter5.Domain.Book5_2;
import com.HibernateRecipes.Chapter5.Domain.Publisher5_2;

/**
 * @author Ignatiues charles arun
 * 
 *         Dec 15, 2010
 */
public class Book5_2DAO
	{

		private static SessionFactory sessionFactory5_2;

		/**
		 * @param args
		 */
		public static void main(String[] args)
			{
				// TODO Auto-generated method stub
				sessionFactory5_2 = SessionManager.getSessionfactory();
				Session session5_2 = sessionFactory5_2.getCurrentSession();
				Transaction tx5_2 = session5_2.beginTransaction();
				Publisher5_2[] pb5_2 = new Publisher5_2[4];
				pb5_2[0] = new Publisher5_2();
				pb5_2[0].setPublisherid(new Long(10));
				pb5_2[0].setPublishername("O'reilly");
				pb5_2[0].setCode("oreilly");
				pb5_2[0].setAddress("USA");

				pb5_2[1] = new Publisher5_2();
				pb5_2[1].setPublisherid(new Long(34));
				pb5_2[1].setPublishername("Wrox");
				pb5_2[1].setCode("wrox");
				pb5_2[1].setAddress("UK");

				Book5_2[] bkCH2 = new Book5_2[4];
				bkCH2[0] = new Book5_2();
				bkCH2[0].setBookid(new Long(40));
				bkCH2[0].setIsbn(new Long(2332));
				bkCH2[0].setName("Beginning XML");
				bkCH2[0].setPrice(new Long(499));
				bkCH2[0].setPublisherid(pb5_2[1]);

				bkCH2[1] = new Book5_2();
				bkCH2[1].setBookid(new Long(20));
				bkCH2[1].setIsbn(new Long(323));
				bkCH2[1].setName("Java for Dummy");
				bkCH2[1].setPrice(new Long(400));

				// session5_2.save(pb5_2[1]);

				// session5_2.saveOrUpdate(pb5_2[0]);
				session5_2.saveOrUpdate(bkCH2[0]);
				session5_2.saveOrUpdate(pb5_2[0]);
				session5_2.saveOrUpdate(bkCH2[1]);
				tx5_2.commit();

			}

	}
